import { globalIgnores } from 'eslint/config';
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript';
import pluginVue from 'eslint-plugin-vue';
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting';

// To allow more languages other than `ts` in `.vue` files, uncomment the following lines:
// import { configureVueProject } from '@vue/eslint-config-typescript'
// configureVueProject({ scriptLangs: ['ts', 'tsx'] })
// More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup

export default defineConfigWithVueTs(
  {
    name: 'app/files-to-lint',
    files: ['**/*.{ts,mts,tsx,vue}']
  },

  globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**', '**/*.min.js', '**/windy/**', 'public/**']),

  pluginVue.configs['flat/essential'],
  vueTsConfigs.recommended,
  skipFormatting,
  // 允许使用any
  {
    name: 'app/custom-rules',
    files: ['**/*.{ts,mts,tsx,vue}'], // 与前面的文件范围一致
    rules: {
      '@typescript-eslint/no-explicit-any': 'off' // 此时会覆盖 recommended 的规则
    }
  },
  // 允许命名为index.vue
  {
    name: 'app/allow-index-component',
    files: ['**/*.vue'], // 仅匹配所有 vue
    rules: {
      'vue/multi-word-component-names': 'off' // 对 index.vue 关闭检查
    }
  },
  // 在 eslint.config.mjs 的自定义规则块中添加
  {
    name: 'app/custom-rules',
    rules: {
      '@typescript-eslint/no-unused-vars': [
        'error',
        {
          args: 'all',
          argsIgnorePattern: '^_',
          caughtErrors: 'all',
          caughtErrorsIgnorePattern: '^_',
          destructuredArrayIgnorePattern: '^_',
          varsIgnorePattern: '^_',
          ignoreRestSiblings: true
        }
      ],
      // vue/block-lang 完整配置
      'vue/block-lang': [
        'error', // 规则级别：error（报错）/ warn（警告）/ off（关闭）
        {
          script: {
            lang: 'ts',
            allowNoLang: true
          }
        }
      ]
    }
  }
);
